/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package service;

import dao.UserDao;
import dao.UserDaoImpl;
import java.util.List;
import java.util.Set;
import myUtils.page.Result;
import po.User;
import po.Organization;
import po.Activity;

/**
 *
 * @author sony
 */
public class UserServiceImpl implements UserService {

    private UserDao userDao;

    public User getUser(int userId) {
        return userDao.getUser(userId);
    }

    public void setUserDao(UserDaoImpl userDao) {
        this.userDao = userDao;
    }

    public void addUser(int id, String password, int type) throws Exception {
        User user = new User();
        user.setId(id);
        user.setPassword(password);
        user.setType(type);
        userDao.save(user);
    }

    public String getSideBar(int id) {
        User usr = getUser(id);
        String sideBar = "";
        int usrType = usr.getType();
        List orgsJoined = this.getOrgJoined(id);
        List orgsLeaded = this.getOrgLeaded(id);
        if (usrType == 1) {
            sideBar += "<h1 class=\"first\">操作列表</h1>";
            sideBar += "<dl class=\"nav3-grid\">";
            sideBar += "<dt><a href=\"uncheckedorg.action\">待审核社团</a></dt>";
            sideBar += "<dt><a href=\"checkedorg.action\">社团列表</a></dt>";
            sideBar += "<dt><a href=\"allNewsList.action\">所有公告</a></dt>";
            sideBar += "<dt><a href=\"#\">站内信</a></dt>";
            sideBar += "<dd><a href=\"mailForm.action\">写新邮件</a></dd>";
            sideBar += "<dd><a href=\"receiveBox.action\">收件箱</a></dd>";
            sideBar += "<dd><a href=\"sendBox.action\">发件箱</a></dd>";
            sideBar += "</dl>";
        } else if (usrType == 2) {
            sideBar += "<h1 class=\"first\">操作列表</h1>";
            sideBar += "<dl class=\"nav3-grid\">";
            sideBar += "<dt><a href=\"userHome.action\">我的首页</a></dt>";
            if (orgsJoined.size() != 0) {
                sideBar += "<dt><a href=\"#\">我参加的社团</a></dt>";
                for (int i = 0; i < orgsJoined.size(); i++) {
                    Organization org = (Organization) orgsJoined.get(i);
                    sideBar += "<dd><a href=\"getorg.action?id=" + org.getId() + "\">" + org.getName() + "</a></dd>";

                }
            }
            if (orgsLeaded.size() != 0) {
                sideBar += "<dt><a href=\"#\">我管理的社团</a></dt>";
                for (int i = 0; i < orgsLeaded.size(); i++) {
                    Organization org = (Organization) orgsLeaded.get(i);
                    sideBar += "<dd><a href=\"getorg.action?id=" + org.getId() + "\">" + org.getName() + "</a></dd>";

                }
            }
            sideBar += "<dt><a href=\"checkedorg.action\">所有社团</a></dt>";
            sideBar += "<dt><a href=\"getUserActivities.action\">我的活动日程表</a></dt>";
            sideBar += "<dt><a href=\"newsList.action\">相关公告</a></dt>";
            sideBar += "<dt><a href=\"#\">站内信</a></dt>";
            sideBar += "<dd><a href=\"mailForm.action\">写新邮件</a></dd>";
            sideBar += "<dd><a href=\"receiveBox.action\">收件箱</a></dd>";
            sideBar += "<dd><a href=\"sendBox.action\">发件箱</a></dd>";
            sideBar += "</dl>";
        }
        return sideBar;
    }

    public List getOrgJoined(int userId) {
        return userDao.getOrgsJoined(userId);
    }

    public List getOrgLeaded(int userId) {
        return userDao.getOrgsLeaded(userId);
    }
    public List getOrgNews(int userId){
        return userDao.getNews(userId);
    }

    public List getMyNews(int userId) {
        return userDao.getMyNews(userId);
    }

    public List getUnreadMails(int userId) {
        return userDao.getUnreadMails(userId);
    }

    public Result getMyNews(int userId, int page) {
        return userDao.getMyNews(userId, page);
    }

    public Result getNews(int userId, int page) {
         return userDao.getNews(userId, page);
    }
}
